package com.jp.algorithm.sort;

public class QuickSort {

    public static void sort(int low, int high, int[] a) {
        if (low >= high)
            return;
        int l = low;
        int h = high;
        int tmp = a[l];
        while (l < h) {
            while(l<h) {
                if(a[h]<tmp){
                    a[l]=a[h];
                    break;
                }else{
                    h--;
                }
            }
            while(l<h) {
                if(a[l] > tmp){
                    a[h]=a[l];
                    break;
                }else{
                    l++;
                }
            }
        }
        a[l]=tmp;
        sort(low,l,a);
        sort(l+1,high,a);
    }

    public static  void print(int[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }

    public static void main(String[] args) {
        int[] a={5,4,19,30,2,10,33,80};
        sort(0,a.length-1,a);
        print(a);
    }
}
